package cn.tedu.csmall.product.repository.impl;

import cn.tedu.csmall.product.pojo.vo.AlbumStandardVo;
import cn.tedu.csmall.product.repository.AlbumCacheRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Repository;

import java.io.Serializable;

@Repository
public class AlbumCacheRepositoryImpl implements AlbumCacheRepository {
    @Autowired
    RedisTemplate<String, Serializable> redisTemplate;

    @Override
    public void save(AlbumStandardVo albumStandardVo) {
        String key = "album"+albumStandardVo.getId();
        redisTemplate.opsForValue().set(key,albumStandardVo);
    }

    @Override
    public void delete(Long id) {
        redisTemplate.delete("album"+id);
    }

    @Override
    public AlbumStandardVo getStandardById(Long id) {
        ValueOperations<String, Serializable> ops = redisTemplate.opsForValue();
        AlbumStandardVo albumStandardVo = (AlbumStandardVo) ops.get("album" + id);
        return albumStandardVo;
    }
}
